//
//  LLOrderView.m
//  UserUse
//
//  Created by Yiwi on 16/10/18.
//  Copyright © 2016年 CJPC. All rights reserved.
//

#import "LLOrderView.h"
#import "LLIncompletedCell.h"
#import "LLCompletedCell.h"
#import "HomeOrderModel.h"

static NSString *reuseIdentifierCell = @"reuseIdentifierCell";

static NSString *reuseCompletedIdentifierCell = @"reuseCompletedIdentifierCell";

@interface LLOrderView()<UITableViewDelegate,UITableViewDataSource>{
    
    NSMutableArray * _datas;
}
@end

@implementation LLOrderView



-(void)setupSubView{
    [self setupTableVeiw];
}
-(void)setupTableVeiw{
    _iTabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenFrameW, kScreenFrameH-kNavigationBarHeight) style:UITableViewStylePlain];
    _iTabelView.backgroundColor = kColoeString(@"f4f4f4");
    _iTabelView.delegate = self;
    _iTabelView.dataSource = self;
    _iTabelView.separatorStyle = UITableViewCellSelectionStyleNone;
    _iTabelView.showsVerticalScrollIndicator = NO;
    [_iTabelView registerClass:[LLIncompletedCell class] forCellReuseIdentifier:reuseIdentifierCell];
      [_iTabelView registerClass:[LLCompletedCell class] forCellReuseIdentifier:reuseCompletedIdentifierCell];
    [self addSubview:_iTabelView];
    // 添加下拉,上拉刷新
    _iTabelView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(reloadFristPageOrderListData)];
    //上拉刷新
    _iTabelView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(reloadNextPageOrderListData)];
}

#pragma mark - tableView协议
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _orderLists.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    HomeOrderModel * order = _orderLists[indexPath.row];
    if([order.order_status isEqualToString:@"订单未完成"]){
        return kScaleNum(140);
    }else{
        return kScaleNum(115);
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HomeOrderModel * order = _orderLists[indexPath.row];
    if([order.order_status isEqualToString:@"订单未完成"]){
        LLCompletedCell * completedCell = [tableView dequeueReusableCellWithIdentifier:reuseCompletedIdentifierCell];
        if (completedCell ==nil){
            completedCell = [[LLCompletedCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseCompletedIdentifierCell];
        }
        completedCell.selectionStyle= UITableViewCellSelectionStyleNone;
        [completedCell setupDataWithOrderlist:order];
        return completedCell;
    }else{
           LLIncompletedCell * incompletedcell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifierCell];
           if (incompletedcell ==nil){
                    incompletedcell = [[LLIncompletedCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifierCell];
            }
            incompletedcell.selectionStyle= UITableViewCellSelectionStyleNone;
            [incompletedcell setupDataWithOrderlist:order];
            return incompletedcell;
    }
   
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.delegate didSelectRowAtIndexPath:indexPath];
}

#pragma maark -LLCompletedCellDelegate
-(void)concalWithListModel:(LLOrderListModel *)listmodel{
    [self.delegate concalWithListModel:listmodel];
}
-(void)completeWithListModel:(LLOrderListModel *)listmodel{
    [self.delegate completeWithListModel:listmodel];
}

-(void)reloadFristPageOrderListData{
    [self.delegate reloadFristPageListData];
}
-(void)reloadNextPageOrderListData{
    [self.delegate reloadNextPageListData];
}
#pragma make -懒加载

-(NSMutableArray *)orderLists{
    if (!_orderLists) {
        _orderLists = [NSMutableArray new];
    }
    return _orderLists;
}

@end
